package com.health.fragment.tijian;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.health.NovaApplication;
import com.health.PersonalFileActivity.onFragmentSave;
import com.health.R;
import com.health.adapter.CheckBoxAdapter;
import com.health.adapter.RadioButtonAdapter;
import com.health.db.FDbManager;
import com.health.fragment.NovaFragment;
import com.health.tablebean.ARCHIVE_BASEINFO;
import com.health.tablebean.ARCHIVE_PHYSICALEXAM;
import com.health.tablebean.BD_DD_INFO;
import com.health.tablebean.SBCL_DATA;
import com.health.activity.tijian.TiJianActivity;
import com.health.tools.GlobalConts;
import com.health.view.spinner.NiceSpinner;
import com.health.widget.MyGridView;
import com.novabluetooth.views.ExamHistoryActivity;

import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * 健康体检--查体信息
 * 
 * @author nova
 *
 */
public class HealthTiJian_CTXXFragment extends NovaFragment implements onFragmentSave {

	protected static final String TAG = "HealthTiJian_CTXXFragment";
	private MyGridView gd_yd;// 眼底
	private MyGridView gd_tzx;// 桶状胸
	private MyGridView gd_hxy;// 呼吸音
	private MyGridView gd_zy;// 杂音
	private MyGridView gd_yt;// 压痛
	private MyGridView gd_bk;// 包块
	private MyGridView gd_gd;// 肝大
	private MyGridView gd_pd;// 脾大
	private MyGridView gd_ydxzy;// 移动性浊音
	private MyGridView gd_rx;// 乳腺
	private MyGridView gd_wy;// 外阴
	private MyGridView gd_yindao;// 阴道
	private MyGridView gd_gj;// 宫颈
	private MyGridView gd_gt;// 宫体
	private MyGridView gd_fj;// 附件

	private NiceSpinner nice_spinner_pf;// 皮肤
	private NiceSpinner nice_spinner_gm;// 巩膜
	private NiceSpinner nice_spinner_lbj;// 淋巴结
	private NiceSpinner nice_spinner_ly;// 啰音
	private NiceSpinner nice_spinner_xl;// 心率
	private NiceSpinner nice_spinner_xzsz;// 下肢水肿
	private NiceSpinner nice_spinner_zdbmbd;// 足背动脉搏动
	private NiceSpinner nice_spinner_gmzz;// 肛门指诊

	private List<BD_DD_INFO> lstbd_pf;
	private List<BD_DD_INFO> lstbd_gm;
	private List<BD_DD_INFO> lstbd_lbj;
	private List<BD_DD_INFO> lstbd_ly;
	private List<BD_DD_INFO> lstbd_xl;
	private List<BD_DD_INFO> lstbd_xzsz;
	private List<BD_DD_INFO> lstbd_zbd;
	private List<BD_DD_INFO> lstd_gmzz;

	private EditText ed_qt_pf;
	private EditText ed_qt_gm;

	private EditText ed_qt_lbj;
	private EditText ed_qt_ly;
	private EditText ed_xl;
	private Button btn_choose_xl;

	private EditText ed_qt_gmzz;
	private EditText ed_qt_last;

	private RadioButtonAdapter adapter_yd;// 眼底
	private RadioButtonAdapter adapter_tzx;// 桶状胸
	private RadioButtonAdapter adapter_hxy;// 呼吸音
	private RadioButtonAdapter adapter_zy;// 杂音
	private RadioButtonAdapter adapter_yt;// 压痛
	private RadioButtonAdapter adapter_bk;// 包块
	private RadioButtonAdapter adapter_gd;// 肝大
	private RadioButtonAdapter adapter_pd;// 脾大
	private RadioButtonAdapter adapter_ydxzy;// 移动性浊音
	private RadioButtonAdapter adapter_wy;// 外阴
	private RadioButtonAdapter adapter_yindao;// 阴道
	private RadioButtonAdapter adapter_gj;// 宫颈
	private RadioButtonAdapter adapter_gt;// 宫体
	private RadioButtonAdapter adapter_fj;// 附件

	private CheckBoxAdapter adapter_rx = null;// 乳腺

	private View healthQuesView = null;
	private FDbManager fdbmanger = null;
	private String str_ydId = "";
	private String str_ydContent = "";
	private String str_tzxId = "";
	// private String str_tzxContent = "";

	private String str_hxyId = "";
	private String str_hxyContent = "";
	private String str_zyId = "";
	private String str_zyContent = "";
	private String str_ytId = "";
	private String str_ytContent = "";
	private String str_bkId = "";
	private String str_bkContent = "";
	private String str_gdId = "";
	private String str_gdContent = "";
	private String str_pdId = "";
	private String str_pdContent = "";
	private String str_ydxzyId = "";
	private String str_ydxzyContent = "";
	private String str_wyId = "";
	private String str_wyContent = "";
	private String str_yindaoId = "";
	private String str_yindaoContent = "";
	private String str_gjId = "";
	private String str_gjContent = "";
	private String str_gtId = "";
	private String str_gtContent = "";
	private String str_fjId = "";
	private String str_fjContent = "";

	private String str_rxId = "";
	private String str_rxContent = "";

	private int from = -1;// from ==1 从基本信息数据库处理 from ==0 第一次保存

	private ARCHIVE_BASEINFO userInfo;// 基本信息
	private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

	// NiceSpinnerAdapter<BD_DD_INFO> nice_adapter_pf = null;
	// NiceSpinnerAdapter<BD_DD_INFO> nice_adapter_gm = null;
	// NiceSpinnerAdapter<BD_DD_INFO> nice_adapter_lbj = null;
	// NiceSpinnerAdapter<BD_DD_INFO> nice_adapter_ly = null;
	// NiceSpinnerAdapter<BD_DD_INFO> nice_adapter_xl = null;
	// NiceSpinnerAdapter<BD_DD_INFO> nice_adapter_xzsz = null;
	// NiceSpinnerAdapter<BD_DD_INFO> nice_adapter_zdbmbd = null;
	// NiceSpinnerAdapter<BD_DD_INFO> nice_adapter_gmzz = null;

	@Override
	public View findViews(LayoutInflater inflater) {
		fdbmanger = NovaApplication.fdbmanger;
		userInfo = NovaApplication.getUserInfo();
		healthQuesView = inflater.inflate(R.layout.healthtijian_ctxx_fragment, null);
		initViews(healthQuesView);

		GlobalConts.setMaxLength(50, ed_qt_pf, ed_qt_gm, ed_qt_lbj, ed_qt_ly, ed_qt_gmzz, ed_qt_last);
		GlobalConts.setMaxLength(3, ed_xl);
		// GlobalConts.setMaxLength(50, ed_xl);//心脏杂音其他、辅助检查其他，其他都是50

		return healthQuesView;
	}

	@Override
	public void setupView(View view) {

	}

	@Override
	public void addListener() {
		btn_choose_xl.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(getActivity(), ExamHistoryActivity.class);
				intent.putExtra("flag", "心率");
				getActivity().startActivityForResult(intent, GlobalConts.RequestMaiLv);
			}
		});

		nice_spinner_gmzz.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
				// TODO Auto-generated method stub
				if (lstd_gmzz.get(position).getDATAINFO().equals("其他")) {
					ed_qt_gmzz.setEnabled(true);
				} else {
					ed_qt_gmzz.setText("");
					ed_qt_gmzz.setEnabled(false);
				}

			}

			@Override
			public void onNothingSelected(AdapterView<?> parent) {
				// TODO Auto-generated method stub

			}
		});

		nice_spinner_ly.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
				// TODO Auto-generated method stub

				if (lstbd_ly.get(position).getDATAINFO().equals("其他")) {
					// }
					// if (position == 4) {
					Log.e(TAG, "lstbd_ly.get(position).getDATAINFO()  其他 ");
					ed_qt_ly.setEnabled(true);
				} else {
					Log.e(TAG, "lstbd_ly.get(position).getDATAINFO() ");
					ed_qt_ly.setText("");
					ed_qt_ly.setEnabled(false);
				}
			}

			@Override
			public void onNothingSelected(AdapterView<?> parent) {
				// TODO Auto-generated method stub

			}
		});

		nice_spinner_pf.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
				if (lstbd_pf.get(position).getDATAINFO().equals("其他")) {
					ed_qt_pf.setEnabled(true);
				} else {
					ed_qt_pf.setEnabled(false);
					ed_qt_pf.setText("");
				}

			}

			@Override
			public void onNothingSelected(AdapterView<?> parent) {
				// TODO Auto-generated method stub

			}
		});

		nice_spinner_gm.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
				if (lstbd_gm.get(position).getDATAINFO().equals("其他")) {
					ed_qt_gm.setEnabled(true);
				} else {
					ed_qt_gm.setEnabled(false);
					ed_qt_gm.setText("");
				}
			}

			@Override
			public void onNothingSelected(AdapterView<?> parent) {

			}
		});

		nice_spinner_lbj.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
				if (lstbd_lbj.get(position).getDATAINFO().equals("其他")) {
					ed_qt_lbj.setEnabled(true);
				} else {
					ed_qt_lbj.setEnabled(false);
					ed_qt_lbj.setText("");
				}

			}

			@Override
			public void onNothingSelected(AdapterView<?> parent) {
				// TODO Auto-generated method stub

			}
		});
	}

	@Override
	public void setData() {
		// //脑血管疾病 PARENTID='DM100-26'
		// //肾脏疾病 PARENTID='DM100-27'
		// //心脏疾病 PARENTID='DM100-28'
		// //血管疾病 PARENTID='DM100-29'
		// //眼部疾病 PARENTID='DM100-30'
		// 神经系统 PARENTID='DM100-31'
		bindDdata("眼底", "PARENTID='DM100-15'");
		bindDdata("有无", "PARENTID='DM01-11'");
		bindDdata("妇科", "PARENTID='DM01-40'");
		bindDdata("桶状胸", "PARENTID='DM01-10'");

		bindDdata("乳腺", "PARENTID='DM100-37'");

		bindSpinner("皮肤", "PARENTID='DM100-36'");
		bindSpinner("巩膜", "PARENTID='DM100-16'");

		bindSpinner("淋巴结", "PARENTID='DM100-17'");
		bindSpinner("啰音", "PARENTID='DM100-18'");
		bindSpinner("心律", "PARENTID='DM100-19'");
		bindSpinner("下肢水肿", "PARENTID='DM100-20'");
		bindSpinner("足背动脉搏动", "PARENTID='DM100-21'");
		bindSpinner("肛门指诊", "PARENTID='DM100-22'");
//		initData();
		setShowData();

	}
	
	public void initData() {
		
		List<ARCHIVE_PHYSICALEXAM> physicalexam = FDbManager.getInstance(getActivity())
				.findAllByWhere(ARCHIVE_PHYSICALEXAM.class, "IDCARD = '" + userInfo.getIDCARD() + "'");
		List<SBCL_DATA> xlList = fdbmanger.findAllByWhere(SBCL_DATA.class, "IDCARD = '" + userInfo.getIDCARD()
		+ "' and " + "CL_TYPE='脉率'" + " and " + "CL_TIME like '" + dateFormat.format(new Date()) + "%'");
		Log.e("xlList", xlList.toString());
		if (physicalexam.size() == 0) {
			if (xlList.size() > 0) {
				ed_xl.setText(xlList.get(xlList.size() - 1).getCL_VALUE().split("次/分钟")[0]);
			}
		}
	}
	@Override
	public void onResume() {
		super.onResume();
//		setData();
	}

	/**
	 * 初始化布局
	 * 
	 * @param v
	 * @author 王婷婷
	 * @date 2015年12月17日 上午10:13:55
	 */
	private void initViews(View v) {
		sex(v);
		gd_yd = (MyGridView) v.findViewById(R.id.gd_yd);
		gd_tzx = (MyGridView) v.findViewById(R.id.gd_tzx);
		gd_hxy = (MyGridView) v.findViewById(R.id.gd_hxy);
		gd_zy = (MyGridView) v.findViewById(R.id.gd_zy);
		gd_yt = (MyGridView) v.findViewById(R.id.gd_yt);
		gd_bk = (MyGridView) v.findViewById(R.id.gd_bk);
		gd_gd = (MyGridView) v.findViewById(R.id.gd_gd);
		gd_pd = (MyGridView) v.findViewById(R.id.gd_pd);
		gd_ydxzy = (MyGridView) v.findViewById(R.id.gd_ydxzy);
		gd_rx = (MyGridView) v.findViewById(R.id.gd_rx);
		gd_wy = (MyGridView) v.findViewById(R.id.gd_wy);
		gd_yindao = (MyGridView) v.findViewById(R.id.gd_yindao);
		gd_gj = (MyGridView) v.findViewById(R.id.gd_gj);
		gd_gt = (MyGridView) v.findViewById(R.id.gd_gt);
		gd_fj = (MyGridView) v.findViewById(R.id.gd_fj);

		nice_spinner_pf = (NiceSpinner) v.findViewById(R.id.nice_spinner_pf);
		nice_spinner_gm = (NiceSpinner) v.findViewById(R.id.nice_spinner_gm);
		nice_spinner_lbj = (NiceSpinner) v.findViewById(R.id.nice_spinner_lbj);
		nice_spinner_ly = (NiceSpinner) v.findViewById(R.id.nice_spinner_ly);
		nice_spinner_xl = (NiceSpinner) v.findViewById(R.id.nice_spinner_xl);
		nice_spinner_xzsz = (NiceSpinner) v.findViewById(R.id.nice_spinner_xzsz);
		nice_spinner_zdbmbd = (NiceSpinner) v.findViewById(R.id.nice_spinner_zdbmbd);
		nice_spinner_gmzz = (NiceSpinner) v.findViewById(R.id.nice_spinner_gmzz);

		ed_qt_pf = (EditText) v.findViewById(R.id.ed_qt_pf);
		ed_qt_gm = (EditText) v.findViewById(R.id.ed_qt_gm);
		ed_qt_lbj = (EditText) v.findViewById(R.id.ed_qt_lbj);
		ed_qt_ly = (EditText) v.findViewById(R.id.ed_qt_ly);
		ed_qt_ly.setEnabled(false);
		ed_xl = (EditText) v.findViewById(R.id.ed_xl);
		btn_choose_xl = (Button) v.findViewById(R.id.btn_choose_xl);
		ed_qt_gmzz = (EditText) v.findViewById(R.id.ed_qt_gmzz);
		ed_qt_last = (EditText) v.findViewById(R.id.ed_qt_last);
		
	}

	/**
	 * 绑定数据值
	 * 
	 * @param str_where
	 * @param flag
	 * @author 王婷婷
	 * @date 2015年12月17日 上午10:30:30
	 */
	private void bindDdata(String flag, String str_where) {
		List<BD_DD_INFO> listZZs = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class, str_where);

		if (flag.equals("有无")) {

			adapter_zy = new RadioButtonAdapter(listZZs, getActivity());
			gd_zy.setAdapter(adapter_zy);
			adapter_yt = new RadioButtonAdapter(listZZs, getActivity());
			gd_yt.setAdapter(adapter_yt);
			adapter_bk = new RadioButtonAdapter(listZZs, getActivity());
			gd_bk.setAdapter(adapter_bk);
			adapter_gd = new RadioButtonAdapter(listZZs, getActivity());
			gd_gd.setAdapter(adapter_gd);
			adapter_pd = new RadioButtonAdapter(listZZs, getActivity());
			gd_pd.setAdapter(adapter_pd);
			adapter_ydxzy = new RadioButtonAdapter(listZZs, getActivity());
			gd_ydxzy.setAdapter(adapter_ydxzy);

		} else if (flag.equals("妇科")) {

			adapter_wy = new RadioButtonAdapter(listZZs, getActivity());
			gd_wy.setAdapter(adapter_wy);
			adapter_yindao = new RadioButtonAdapter(listZZs, getActivity());
			gd_yindao.setAdapter(adapter_yindao);
			adapter_gj = new RadioButtonAdapter(listZZs, getActivity());
			gd_gj.setAdapter(adapter_gj);
			adapter_gt = new RadioButtonAdapter(listZZs, getActivity());
			gd_gt.setAdapter(adapter_gt);
			adapter_fj = new RadioButtonAdapter(listZZs, getActivity());
			gd_fj.setAdapter(adapter_fj);

		} else if (flag.equals("眼底")) {

			adapter_yd = new RadioButtonAdapter(listZZs, getActivity());
			gd_yd.setAdapter(adapter_yd);
			adapter_hxy = new RadioButtonAdapter(listZZs, getActivity());
			gd_hxy.setAdapter(adapter_hxy);

		} else if (flag.equals("桶状胸")) {

			adapter_tzx = new RadioButtonAdapter(listZZs, getActivity());
			adapter_tzx.setOtherTextVisible(false);
			gd_tzx.setAdapter(adapter_tzx);

		} else if (flag.equals("乳腺")) {

			adapter_rx = new CheckBoxAdapter(getActivity(), listZZs);
			adapter_rx.setOtherMaxLength(50);
			gd_rx.setAdapter(adapter_rx);
		}
	}

	/**
	 * 获取转诊的信息
	 * 
	 * @author 王婷婷
	 * @date 2015年12月16日 下午3:10:48
	 */
	private void getRadioButtonCheckedData() {
		str_ydId = adapter_yd.getChecked();
		str_ydContent = adapter_yd.getCheckedOther();
		str_tzxId = adapter_tzx.getChecked();
		// str_tzxContent = adapter_tzx.getCheckedOther();

		str_hxyId = adapter_hxy.getChecked();
		str_hxyContent = adapter_hxy.getCheckedOther();
		str_zyId = adapter_zy.getChecked();
		str_zyContent = adapter_zy.getCheckedOther();
		str_ytId = adapter_yt.getChecked();
		str_ytContent = adapter_yt.getCheckedOther();
		str_bkId = adapter_bk.getChecked();
		str_bkContent = adapter_bk.getCheckedOther();
		str_gdId = adapter_gd.getChecked();
		str_gdContent = adapter_gd.getCheckedOther();
		str_pdId = adapter_pd.getChecked();
		str_pdContent = adapter_pd.getCheckedOther();
		str_ydxzyId = adapter_ydxzy.getChecked();
		str_ydxzyContent = adapter_ydxzy.getCheckedOther();
		str_wyId = adapter_wy.getChecked();
		str_wyContent = adapter_wy.getCheckedOther();
		str_yindaoId = adapter_yindao.getChecked();
		str_yindaoContent = adapter_yindao.getCheckedOther();
		str_gjId = adapter_gj.getChecked();
		str_gjContent = adapter_gj.getCheckedOther();
		str_gtId = adapter_gt.getChecked();
		str_gtContent = adapter_gt.getCheckedOther();
		str_fjId = adapter_fj.getChecked();
		str_fjContent = adapter_fj.getCheckedOther();

	}

	/**
	 * 获取 被选中的checkbox
	 * 
	 * @author 王婷婷
	 * @date 2015年12月19日 上午11:34:30
	 */
	private void getCheckBoxedData() {

		str_rxId = adapter_rx.getCheckedIdsStr();
		str_rxContent = adapter_rx.getOther();

	}

	private int getListIndex(String str, List<BD_DD_INFO> bds) {
		for (int i = 0; i < bds.size(); i++) {
			if (str.equals(bds.get(i).getID())) {
				return i;
			}
		}
		return 0;
	}

	/**
	 * 保存数据
	 * 
	 * @author 王婷婷
	 * @date 2015年12月17日 上午11:13:39
	 */
	private void saveData() {

		ARCHIVE_PHYSICALEXAM ques = new ARCHIVE_PHYSICALEXAM();

		ques.setIDCARD(userInfo.getIDCARD());
		ques.setEYEROUND(str_ydId);
		ques.setEYEROUND_EX(str_ydContent);

		// 皮肤
		int nice_spinner_pf_pos = nice_spinner_pf.getSelectedIndex();
		Log.w("dddddddddnice_spinner_culture_pos2", "tt--" + nice_spinner_pf_pos);

		ques.setSKIN(lstbd_pf.get(nice_spinner_pf.getSelectedIndex()).getID());// 皮肤
		ques.setSKIN_EX(ed_qt_pf.getText().toString());

		// 巩膜
		int nice_spinner_gm_pos = nice_spinner_gm.getSelectedIndex();
		Log.w("dddddddddnice_spinner_culture_pos2", "tt--" + nice_spinner_gm_pos);

		// if (nice_spinner_gm_pos != 0) {
		// nice_spinner_gm_pos_str =
		// nice_adapter_gm.getItem(nice_spinner_gm_pos).getID();
		// }

		ques.setSCLERA(lstbd_gm.get(nice_spinner_gm.getSelectedIndex()).getID());// 巩膜
		ques.setSCLERE_EX(ed_qt_gm.getText().toString());

		// 淋巴结
		int nice_spinner_lbj_pos = nice_spinner_lbj.getSelectedIndex();
		Log.w("dddddddddnice_spinner_culture_pos2", "tt--" + nice_spinner_lbj_pos);

		// if (nice_spinner_lbj_pos != 0) {
		// nice_spinner_lbj_pos_str =
		// nice_adapter_lbj.getItem(nice_spinner_lbj_pos).getID();
		// }

		ques.setLYMPH(lstbd_lbj.get(nice_spinner_lbj.getSelectedIndex()).getID());// 淋巴结
		ques.setLYMPH_EX(ed_qt_lbj.getText().toString());// 淋巴结其他

		// TODO
		// private EditText ed_qt;
		// private EditText ed_qt_gm;
		//
		// private Button btn_choose_xl;

		ques.setBARRELCHEST(str_tzxId);// 桶状胸
		ques.setBREATHSOUNDS(str_hxyId);
		ques.setBREATHSOUNDS_EX(str_hxyContent);

		//
		int nice_spinner_ly_pos = nice_spinner_ly.getSelectedIndex();
		Log.w("dddddddddnice_spinner_culture_pos2", "tt--" + nice_spinner_ly_pos);

		// if (nice_spinner_ly_pos != 0) {
		// nice_spinner_ly_pos_str =
		// nice_adapter_ly.getItem(nice_spinner_ly_pos).getID();
		// }

		ques.setRALE(lstbd_ly.get(nice_spinner_ly.getSelectedIndex()).getID());// 啰音

		ques.setRALE_EX(ed_qt_ly.getText().toString());// 啰音--其他
		ques.setHEARTRATE(ed_xl.getText().toString());// 心率

		// 心律
		int nice_spinner_xl_pos = nice_spinner_xl.getSelectedIndex();
		Log.w("dddddddddnice_spinner_culture_pos2", "tt--" + nice_spinner_xl_pos);

		// if (nice_spinner_xl_pos != 0) {
		// nice_spinner_xl_pos_str =
		// nice_adapter_xl.getItem(nice_spinner_xl_pos).getID();
		// }

		ques.setHEARTRHYTHM(lstbd_xl.get(nice_spinner_xl.getSelectedIndex()).getID());// 心律不齐
		ques.setNOISE(str_zyId);// 杂音
		ques.setNOISE_EX(str_zyContent);

		ques.setENCLOSEDMASS(str_bkId);// 包块
		ques.setENCLOSEDMASS_EX(str_bkContent);

		// 下肢水肿
		int nice_spinner_xzsz_pos = nice_spinner_xzsz.getSelectedIndex();
		Log.w("dddddddddnice_spinner_culture_pos2", "tt--" + nice_spinner_xzsz_pos);

		// if (nice_spinner_xzsz_pos != 0) {
		// nice_spinner_xzsz_pos_str =
		// nice_adapter_xzsz.getItem(nice_spinner_xzsz_pos).getID();
		// }

		ques.setEDEMA(lstbd_xzsz.get(nice_spinner_xzsz.getSelectedIndex()).getID());// 下肢水肿

		// 足背动脉搏动
		int nice_spinner_zbd_pos = nice_spinner_zdbmbd.getSelectedIndex();
		Log.w("dddddddddnice_spinner_culture_pos2", "tt--" + nice_spinner_zbd_pos);

		// if (nice_spinner_zbd_pos != 0) {
		// nice_spinner_zbd_pos_str =
		// nice_adapter_zdbmbd.getItem(nice_spinner_zbd_pos).getID();
		// }

		ques.setFOOTBACK(lstbd_zbd.get(nice_spinner_zdbmbd.getSelectedIndex()).getID());// 足背动脉搏动

		int nice_spinner_gmzz_pos = nice_spinner_gmzz.getSelectedIndex();
		Log.w("dddddddddnice_spinner_culture_pos2", "tt--" + nice_spinner_gmzz_pos);

		// if (nice_spinner_gmzz_pos != 0) {
		// nice_spinner_gmzz_pos_str =
		// nice_adapter_gmzz.getItem(nice_spinner_gmzz_pos).getID();
		// }

		ques.setANUS(lstd_gmzz.get(nice_spinner_gmzz.getSelectedIndex()).getID());// 肛门指诊
		ques.setANUS_EX(ed_qt_gmzz.getText().toString());

		ques.setBREAST(str_rxId);
		ques.setBREAST_EX(str_rxContent);
		ques.setVULVA(str_wyId);

		ques.setVULVA_EX(str_wyContent);
		ques.setVAGINA(str_yindaoId);
		ques.setVAGINA_EX(str_yindaoContent);

		ques.setENCLOSEDMASS(str_bkId);// 包块
		ques.setENCLOSEDMASS_EX(str_bkContent);
		ques.setCERVIXUTERI(str_gjId);
		ques.setCERVIXUTERI_EX(str_gjContent);
		ques.setCORPUS(str_gtId);

		ques.setCORPUS_EX(str_gtContent);
		ques.setATTACH(str_fjId);
		ques.setATTACH_EX(str_fjContent);

		ques.setOTHER(ed_qt_last.getText().toString());// 其他
		ques.setPRESSPAIN(str_ytId);
		ques.setPRESSPAIN_EX(str_ytContent);

		ques.setLIVER(str_gdId);
		ques.setLIVER_EX(str_gdContent);
		ques.setSPLEEN(str_pdId);

		ques.setSPLEEN_EX(str_pdContent);
		ques.setVOICED(str_ydxzyId);

		ques.setVOICED_EX(str_ydxzyContent);
		ques.setVAGINA(str_yindaoId);
		ques.setVAGINA_EX(str_yindaoContent);

		ques.setENCLOSEDMASS(str_bkId);// 包块
		ques.setENCLOSEDMASS_EX(str_bkContent);
		ques.setCERVIXUTERI(str_gjId);
		ques.setCERVIXUTERI_EX(str_gjContent);
		ques.setCORPUS(str_gtId);

		ques.setCORPUS_EX(str_gtContent);
		ques.setATTACH(str_fjId);
		ques.setATTACH_EX(str_fjContent);

		if (from == 1) {
			fdbmanger.updata(ques, "IDCARD='" + userInfo.getIDCARD() + "'");
		} else {
			fdbmanger.save(ques);
			from = 1;
		}
		((TiJianActivity) getActivity()).showTextDialog("保存成功");

	}

	/**
	 * 设置展示的信息
	 * 
	 * @author 王婷婷
	 * @date 2015年12月17日 上午11:31:24
	 */
	private void setShowData() {
		List<ARCHIVE_PHYSICALEXAM> queses = fdbmanger.findAllByWhere(ARCHIVE_PHYSICALEXAM.class,
				"IDCARD='" + userInfo.getIDCARD() + "'");
		if (queses.size() > 0) {
			from = 1;
			ARCHIVE_PHYSICALEXAM ques = queses.get(0);

			str_ydId = ques.getEYEROUND();
			str_ydContent = ques.getEYEROUND_EX();
			adapter_yd.setChecked(str_ydId, str_ydContent);

			str_tzxId = ques.getBARRELCHEST();
			adapter_tzx.setChecked(str_tzxId);
			// private String str_tzxContent = "";

			str_hxyId = ques.getBREATHSOUNDS();
			str_hxyContent = ques.getBREATHSOUNDS_EX();
			adapter_hxy.setChecked(str_hxyId, str_hxyContent);

			str_zyId = ques.getNOISE();
			str_zyContent = ques.getNOISE_EX();
			adapter_zy.setChecked(str_zyId, str_zyContent);

			str_ytId = ques.getPRESSPAIN();
			str_ytContent = ques.getPRESSPAIN_EX();
			adapter_yt.setChecked(str_ytId, str_ytContent);

			str_bkId = ques.getENCLOSEDMASS();
			str_bkContent = ques.getENCLOSEDMASS_EX();
			adapter_bk.setChecked(str_bkId, str_bkContent);

			str_gdId = ques.getLIVER();
			str_gdContent = ques.getLIVER_EX();
			adapter_gd.setChecked(str_gdId, str_gdContent);

			str_pdId = ques.getSPLEEN();
			str_pdContent = ques.getSPLEEN_EX();
			adapter_pd.setChecked(str_pdId, str_pdContent);

			str_ydxzyId = ques.getVOICED();
			str_ydxzyContent = ques.getVOICED_EX();
			adapter_ydxzy.setChecked(str_ydxzyId, str_ydxzyContent);

			str_wyId = ques.getVULVA();
			str_wyContent = ques.getVULVA_EX();
			adapter_wy.setChecked(str_wyId, str_wyContent);

			str_yindaoId = ques.getVAGINA();
			str_yindaoContent = ques.getVAGINA_EX();
			adapter_yindao.setChecked(str_yindaoId, str_yindaoContent);

			str_gjId = ques.getCERVIXUTERI();
			str_gjContent = ques.getCERVIXUTERI_EX();
			adapter_gj.setChecked(str_gjId, str_gjContent);

			str_gtId = ques.getCORPUS();
			str_gtContent = ques.getCORPUS_EX();
			adapter_gt.setChecked(str_gtId, str_gtContent);

			str_fjId = ques.getATTACH();
			str_fjContent = ques.getATTACH_EX();
			adapter_fj.setChecked(str_fjId, str_fjContent);
			str_rxId = ques.getBREAST();
			str_rxContent = ques.getBREAST_EX();
			adapter_rx.setChecked(str_rxId);
			adapter_rx.setOther(str_rxContent);

			ed_qt_pf.setText(ques.getSKIN_EX());
			ed_qt_gm.setText(ques.getSCLERE_EX());

			ed_qt_lbj.setText(ques.getLYMPH_EX());
			ed_qt_ly.setText(ques.getRALE_EX());
			ed_xl.setText(ques.getHEARTRATE());

			ed_qt_gmzz.setText(ques.getANUS_EX());
			ed_qt_last.setText(ques.getOTHER());

			if (TextUtils.isEmpty(ques.getSKIN_EX())) {
				ed_qt_pf.setEnabled(false);
			}

			if (TextUtils.isEmpty(ques.getSCLERE_EX())) {
				ed_qt_gm.setEnabled(false);
			}

			if (TextUtils.isEmpty(ques.getLYMPH_EX())) {
				ed_qt_lbj.setEnabled(false);
			}

			if (TextUtils.isEmpty(ques.getANUS_EX())) {
				ed_qt_gmzz.setEnabled(false);
			}

			// 皮肤
			// lstbd_pf = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
			// "ID='" + ques.getSKIN() + "'");
			// if (lstbd_pf.size() > 0) {
			// nice_spinner_pf_pos_str = lstbd_pf.get(0).getID();
			nice_spinner_pf.setSelectedIndex(getListIndex(ques.getSKIN(), lstbd_pf));// Text(lstbd_pf.get(0).getDATAINFO());
			// }

			// 巩膜
			// lstbd_gm = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
			// "ID='" + ques.getSCLERA() + "'");
			// if (lstbd_gm.size() > 0) {
			// nice_spinner_gm_pos_str = lstbd_gm.get(0).getID();
			nice_spinner_gm.setSelectedIndex(getListIndex(ques.getSCLERA(), lstbd_gm));// Text(lstbd_gm.get(0).getDATAINFO());
			// }

			// 淋巴结
			// lstbd_lbj = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
			// "ID='" + ques.getLYMPH() + "'");
			// if (lstbd_lbj.size() > 0) {
			// nice_spinner_lbj_pos_str = lstbd_lbj.get(0).getID();
			nice_spinner_lbj.setSelectedIndex(getListIndex(ques.getLYMPH(), lstbd_lbj));// Text(lstbd_lbj.get(0).getDATAINFO());
			// }

			// 啰音
			// lstbd_ly = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
			// "ID='" + ques.getRALE() + "'");
			// if (lstbd_ly.size() > 0) {
			// nice_spinner_ly_pos_str = lstbd_ly.get(0).getID();
			int nsly = getListIndex(ques.getRALE(), lstbd_ly);
			nice_spinner_ly.setSelectedIndex(nsly);// Text(lstbd_ly.get(0).getDATAINFO());
			// if (nsly == 0) {
			// ed_qt_ly.setText("");
			// ed_qt_ly.setEnabled(false);
			// } else {
			// ed_qt_ly.setEnabled(true);
			// ed_qt_ly.setFocusable(true);
			// }
			// }
			if ("其他".equals(lstbd_ly.get(nsly).getDATAINFO())) {
				ed_qt_ly.setEnabled(true);
			}
			// 心律
			// lstbd_xl = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
			// "ID='" + ques.getHEARTRHYTHM() + "'");
			// if (lstbd_xl.size() > 0) {
			// nice_spinner_xl_pos_str = lstbd_xl.get(0).getID();
			nice_spinner_xl.setSelectedIndex(getListIndex(ques.getHEARTRHYTHM(), lstbd_xl));// Text(lstbd_xl.get(0).getDATAINFO());
			// }

			// 下肢水肿
			// lstbd_xzsz = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
			// "ID='" + ques.getEDEMA() + "'");
			// if (lstbd_xzsz.size() > 0) {
			// nice_spinner_xzsz_pos_str = lstbd_xzsz.get(0).getID();
			nice_spinner_xzsz.setSelectedIndex(getListIndex(ques.getEDEMA(), lstbd_xzsz));// Text(lstbd_xzsz.get(0).getDATAINFO());
			// }

			// 下肢水肿
			// lstbd_zbd = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
			// "ID='" + ques.getFOOTBACK() + "'");
			// if (lstbd_zbd.size() > 0) {
			// nice_spinner_zbd_pos_str = lstbd_zbd.get(0).getID();
			nice_spinner_zdbmbd.setSelectedIndex(getListIndex(ques.getFOOTBACK(), lstbd_zbd));// Text(lstbd_zbd.get(0).getDATAINFO());
			// }

			// 肛门指诊
			// blstd_gmzz = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
			// "ID='" + ques.getANUS() + "'");
			// if (blstd_gmzz.size() > 0) {
			// nice_spinner_gmzz_pos_str = blstd_gmzz.get(0).getID();
			nice_spinner_gmzz.setSelectedIndex(getListIndex(ques.getANUS(), lstd_gmzz));// Text(blstd_gmzz.get(0).getDATAINFO());
			// }

		} else {
			from = 0;
		}

	}

	@Override
	public void save() {
		getRadioButtonCheckedData();
		getCheckBoxedData();
		saveData();

	}

	/**
	 * 设置下拉
	 * 
	 * @param flagName
	 * @param strSql
	 * @author 王婷婷
	 * @date 2015年12月24日 上午9:19:28
	 */

	private void bindSpinner(String flagName, String strSql) {
		List<BD_DD_INFO> sList = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class, strSql);
		if (flagName.equals("皮肤")) {
			// nice_adapter_pf = new NiceSpinnerAdapter<>(getActivity(), sList);
			// nice_spinner_pf.setAdapter(nice_adapter_pf);
			lstbd_pf = sList;
			nice_spinner_pf.attachDataSource(lstbd_pf);
		} else if (flagName.equals("巩膜")) {
			lstbd_gm = sList;
			// nice_adapter_gm = new NiceSpinnerAdapter<>(getActivity(), sList);
			nice_spinner_gm.attachDataSource(lstbd_gm);

		} else if (flagName.equals("淋巴结")) {
			// nice_adapter_lbj = new NiceSpinnerAdapter<>(getActivity(),
			// sList);
			lstbd_lbj = sList;
			nice_spinner_lbj.attachDataSource(lstbd_lbj);

		} else if (flagName.equals("啰音")) {

			// nice_adapter_ly = new NiceSpinnerAdapter<>(getActivity(), sList);
			lstbd_ly = sList;
			nice_spinner_ly.attachDataSource(lstbd_ly);

		} else if (flagName.equals("心律")) {
			// nice_adapter_xl = new NiceSpinnerAdapter<>(getActivity(), sList);
			lstbd_xl = sList;
			nice_spinner_xl.attachDataSource(lstbd_xl);

		} else if (flagName.equals("下肢水肿")) {
			// nice_adapter_xzsz = new NiceSpinnerAdapter<>(getActivity(),
			// sList);
			lstbd_xzsz = sList;
			nice_spinner_xzsz.attachDataSource(lstbd_xzsz);

		} else if (flagName.equals("足背动脉搏动")) {
			// nice_adapter_zdbmbd = new NiceSpinnerAdapter<>(getActivity(),
			// sList);
			lstbd_zbd = sList;
			nice_spinner_zdbmbd.attachDataSource(lstbd_zbd);
		} else if (flagName.equals("肛门指诊")) {
			// nice_adapter_gmzz = new NiceSpinnerAdapter<>(getActivity(),
			// sList);
			int size = sList.size();
			if (size>0) {
				lstd_gmzz = new ArrayList<BD_DD_INFO>();
				for (int i = 0; i < size; i++) {
					String str_id = sList.get(i).getID();
					if (str_id.equals("DM100-22_1") || str_id.equals("DM100-22_2") || str_id.equals("DM100-22_3")
							|| str_id.equals("DM100-22_4")|| str_id.equals("DM100-22_9")) {
						lstd_gmzz.add(sList.get(i));
					}
				}
			}
			nice_spinner_gmzz.attachDataSource(lstd_gmzz);

		}

	}

	@Override
	public void setNiaoYeFenxi(String niaoDanYuan, String qianXue, String DanHongSu, String tongti, String puTaoTang,
			String danBaiZhi, String PH, String yaXiaoSuan, String baiXiBao, String biZhong, String weiShengSu) {
		// TODO Auto-generated method stub

	}

	@Override
	public void setMaiLv(String mailv) {
		ed_xl.setText(mailv);
	}
	// @Override
	// public void setXinLv(String mailv) {
	// ed_xl.setText(mailv);
	// }
	
	/**
	 * 查体信息Frgament中根据性别隐藏/显示妇科查体项
	 * 
	 * @param baseView
	 */
	private void sex(View baseView) {
		if (baseView == null || userInfo == null) {
			return;
		}
		// 1:男,2:女,0:未知的性别,9:未说明的性,DM01-08_1:男
		String sex = userInfo.getSEX();
		// 妇科标题
		TextView tv_fuke = (TextView) baseView.findViewById(R.id.tv_fuke);
		// 妇科内容
		LinearLayout ll_fuke = (LinearLayout) baseView.findViewById(R.id.ll_fuke);
		if (sex == null || tv_fuke == null || ll_fuke == null) {
			return;
		}
		if ("1".equals(sex)) {
			tv_fuke.setVisibility(View.GONE);
			ll_fuke.setVisibility(View.GONE);
		} else if ("2".equals(sex)) {
			tv_fuke.setVisibility(View.VISIBLE);
			ll_fuke.setVisibility(View.VISIBLE);
		} else if ("DM01-08_1".equals(sex)) {
			tv_fuke.setVisibility(View.GONE);
			ll_fuke.setVisibility(View.GONE);
		} else {
			tv_fuke.setVisibility(View.VISIBLE);
			ll_fuke.setVisibility(View.VISIBLE);
		}
	}
}
